import time

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

from utils.webdriver_factory import WebDriverFactory

# 模拟鼠标操作

driver = WebDriverFactory.get_instance()
driver.maximize_window()
driver.get("http://www.baidu.com")
search_button = driver.find_element(By.ID, "su")
print(search_button)
action_chain = ActionChains(driver=driver)
# ActionChains会将动作添加到队列中，等待调用perform方法后开始依次执行
# 移动到目标元素
action_chain.move_to_element(search_button)
# 单击
# action_chain.click(search_button)
# 双击
# action_chain.double_click(search_button)
# 右击
# action_chain.context_click(search_button)
# 单击不释放
action_chain.click_and_hold(search_button)
# 释放
action_chain.release(search_button)
# 立即执行动作链
action_chain.perform()

time.sleep(1)
